<template>
	<view class="page">
		<navigation textColor="#333333" barColor="#333333" defaultButton="back">选择公司</navigation>
		<view class="page_main">
			<form-picker name="选择公司" v-model="model.id" placeholder="请选择选择公司" rangeKey="name" rangeValue="id" :range="orgList"></form-picker>
			<form-input name="姓名" v-model="model.corpName" placeholder="请输入您的姓名"></form-input>
			<view class="form-item mask_line">
				<view class="form-item__name">验证理由</view>
				<view class="form-item__value">
					<textarea
						class="form-item__value-input left_input"
						v-model="model.companyMessage"
						placeholder-class="form-item__value-input-placeholder"
						placeholder="建议您申请后告知公司管理员进行审核哦～"
					/>
				</view>
			</view> 
			<button class="page_btn" hover-class="page_btn-hover" @tap="submit">确认提交</button>
			<view class="hint">申请后公司管理员审核通过即刻进入该公司</view>
		</view>
	</view>
</template>

<script>
import * as commonApi from '@/api/common.js';
import * as orgApi from '@/api/orgApi/org.js';
export default {
	data() {
		return {
			userInfo: this.$store.getters.getUserInfo,
			model: {
				id: '',
				corpName: '',
				companyMessage: '',
				instituteType: 0,//注册类型 0-进入已有公司 1-申请新服务商
			},
			orgList: []
		};
	},
	onShow() {
		this.getOrgAllList();
		// this.userInfo=uni.getStorageSync('open')
	},
	methods: {
		submit() {
			let model = JSON.parse(JSON.stringify(this.model));
			model.openId = this.userInfo.openId || '';
			model.phone = this.userInfo.phone || '';
			model.wxAvatar = this.userInfo.wxAvatar || '';
			model.wxNickname = this.userInfo.wxNickname || '';
			orgApi
				.newOrg(model)
				.then(res => {
					if (res.code === 0) {
						uni.reLaunch({
							url: '/pages/system/getPhoneNumber'
						});
					}
				})
				.catch(e => {
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
				});
		},
		getOrgAllList() {
			commonApi
				.getOrgAllList()
				.then(res => {
					if (res.code === 0) {
						this.orgList = res.data;
					}
				})
				.catch(e => {
					uni.showToast({
						title: e.msg,
						icon: 'none',
						duration: 1000
					});
				});
		}
	}
};
</script>

<style lang="stylus">
.hint
	text-align center
	font-size 24rpx
	font-family PingFang SC
	font-weight 400
	color #999999
	margin-top 20rpx
.page_btn
	margin-top 120rpx
.page_main
	padding 0rpx 30rpx
	box-sizing border-box
.mask_line
	flex-direction column
	position relative
	padding-top 30rpx
	box-sizing border-box
	.form-item__name
		width 100%
		text-align left
	.form-item__value
		width 100%
		.form-item__value-input
			width 100%
			height 100rpx
			margin 0rpx
			padding 20rpx 0rpx
			text-align left
			box-sizing border-box
		.form-item__value-input-placeholder
			text-align left
</style>
